<?php

declare (strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://doc.hyperf.io
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
 */
namespace App\Task;

use App\Component\Server;
use App\Constants\Atomic;
use App\Constants\MemoryTable;
use App\Constants\WsMessage;
use Hyperf\Memory\AtomicManager;
use Hyperf\Memory\TableManager;
use Hyperf\Task\Annotation\Task;
use Hyperf\WebSocketServer\Sender;
use function App\Helper\wsSuccess;
class UserTask_329b5358ae8923482aea67b5de291920 extends UserTask
{
    use \Hyperf\Di\Aop\ProxyTrait;
    /**
     * @Task()
     * @param int $fd
     * @param     $data
     */
    public function unReadApplicationCount(int $fd, $data)
    {
        $__function__ = __FUNCTION__;
        $__method__ = __METHOD__;
        return self::__proxyCall(UserTask::class, __FUNCTION__, self::getParamsMap(UserTask::class, __FUNCTION__, func_get_args()), function (int $fd, $data) use($__function__, $__method__) {
            $result = wsSuccess(WsMessage::WS_MESSAGE_CMD_EVENT, WsMessage::EVENT_GET_UNREAD_APPLICATION_COUNT, $data);
            $sender = make(Sender::class);
            $sender->push($fd, $result);
        });
    }
    /**
     * @Task()
     */
    public function onlineNumber()
    {
        $__function__ = __FUNCTION__;
        $__method__ = __METHOD__;
        return self::__proxyCall(UserTask::class, __FUNCTION__, self::getParamsMap(UserTask::class, __FUNCTION__, func_get_args()), function () use($__function__, $__method__) {
            $atomic = AtomicManager::get(Atomic::NAME);
            $userToFdTable = TableManager::get(MemoryTable::USER_TO_FD);
            $fds = [];
            foreach ($userToFdTable as $item) {
                array_push($fds, $item['fd']);
            }
            $data = wsSuccess(WsMessage::WS_MESSAGE_CMD_EVENT, 'onlineNumber', "<span>当前在线人数：<b>{$atomic->get()}</b></span>");
            Server::sendToAll($data, $fds);
        });
    }
    /**
     * @Task()
     * @param array $fds
     * @param array $data
     *
     * @return bool
     */
    public function setUserStatus(array $fds, array $data)
    {
        $__function__ = __FUNCTION__;
        $__method__ = __METHOD__;
        return self::__proxyCall(UserTask::class, __FUNCTION__, self::getParamsMap(UserTask::class, __FUNCTION__, func_get_args()), function (array $fds, array $data) use($__function__, $__method__) {
            if (empty($fds)) {
                return false;
            }
            $result = wsSuccess(WsMessage::WS_MESSAGE_CMD_EVENT, WsMessage::EVENT_USER_STATUS, $data);
            Server::sendToAll($result, $fds);
            return true;
        });
    }
}